﻿using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;

namespace Web.Models
{

    public class CategoryIds
    {
        public static int News => 1;
    }

    public class Category : Entity
    {
        [Key]
        public int Id { get; set; }

        [Required]
        [MaxLength(50)]
        [DisplayName("名称")]
        public string CategoryName { get; set; }

        [DisplayName("英文名称")]
        [MaxLength(50)]
        public string CategoryNameEn { get; set; }

        [DisplayName("上级")]
        public int? ParentId { get; set; }

        [DisplayName("多层上级")]
        public string ParentIds { get; set; }

        [DisplayName("排序")]
        [Required]
        public int OrderId { get; set; }

        [DisplayName("缩略图")]
        [MaxLength(255)]
        public string SmallPicture { get; set; }

        /// <summary>
        /// 字体图标,直接输入css名
        /// </summary>
        [DisplayName("图标")]
        [StringLength(20)]
        public string Icon { get; set; }

        [NotMapped]
        public List<int> ParentIdList
        {
            get
            {
                List<int> list = new List<int>();
                if (!string.IsNullOrEmpty(ParentIds))
                {
                    list.AddRange(from item in ParentIds.Split(',') where Com.Core.Helps.ValidateHelper.IsNumeric(item) select int.Parse(item));
                }
                return list;
            }
        }
    }
}
